home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / lvswin.zip / WINOBJ.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-03  |  11.2 KB  |  241 lines

  1. /*
  2.  *            LVS Windows
  3.  *      The Window Class System
  4.  *
  5.  *        Copyright 1991 (c), Lake View Software
  6.  *                            4321 Harborough Rd.
  7.  *                            Columbus, OH 43220
  8.  *        All rights reserved.
  9.  */
  10. // WinObj.hpp
  11.  
  12. #ifndef WINOBJ_HPP
  13. #define WINOBJ_HPP
  14.  
  15. #include <stdio.h>
  16. #include "win.h"
  17.  
  18. typedef int (*valid_func)(void *);
  19. typedef void (*before_func)(void *);
  20. typedef void (*mouse_routine_t)(int, int);
  21.  
  22. // Get Object
  23. class GetObj {
  24.         friend class WinObj;
  25.         GetObj *Prev_get;
  26.         GetObj *Next_get;
  27.         int y, x;
  28.         int len, dec;
  29.         int type;           // Type of data
  30.         void *obj;          // Data pointer
  31.         char style;         // Style for strings
  32.         char *picture;      // Picture to use for strings
  33.         valid_func valid;   // Call after read to get
  34.         before_func before; // Call before read to get
  35.         int help_level;     // Help to use
  36.         int Hot_Key;        // Key to trigger a user popup
  37.  
  38.                 /* Paradox Stuf */
  39.         unsigned PX_rec;    // Paradox record handle
  40.         unsigned PX_tbl;    // Paradox table handle
  41.         unsigned PX_fld;    // Paradox field handle
  42.         char PX_type [10];  // Paradox field type
  43.         void *PX_buf;       // temp Buffer for px field
  44. };
  45.  
  46.  
  47. // Window Object
  48. class WinObj  {
  49.     friend class WinMouse;
  50.     friend WinObj *Win_whos_active ();
  51.     friend void Win_close_all ();
  52.     protected:
  53.         static WinObj *w_active;        // Current active window object
  54.         static int w_count;             // number of window objects
  55.         WinObj *next_win;               // Next window object
  56.         WinObj *prev_win;               // Previous window object
  57.         int wsc,wsr,wec,wer;            // Screen coordinates
  58.         int width,height;               // Actual screen space available
  59.         int get_attr;                   // Get attribute
  60.         int win_attr;                   // Window attribute
  61.         int bor_attr;                   // Border attribute
  62.         int bor_type;                   // Border type
  63.         int win_type;                   // type of window
  64.         char fill_char;                 // window fill character
  65.         int title_pos;                  // Title position
  66.         char *title_str;                // Pointer to title string
  67.         char *wdata_buf;                // Data buffer
  68.         char *wattr_buf;                // attribute buffer
  69.         GetObj *Current_get;            // Current get object
  70.         GetObj *Last_get;               // Last get object in list
  71.         char opened;                    // Opened flag
  72.         char hidden;                    // Hidden flag
  73.         char needs_display;             // Refresh flag
  74.         char has_border;                // border flag
  75.         char has_shadow;                // shadow flag
  76.         char any_change;                // any read changes
  77.         char scroll_h,scroll_v;         // scroll arrows flag
  78.         unsigned vh,vw;                 // Virtual height and width
  79.         unsigned buf_size;              // Window data and attr buf size
  80.         unsigned sx,sy;                 // Start x and y for virtual display
  81.         unsigned cur_pos;               // Cursor x and y
  82.         void reset_window ();           // reset all flags
  83.         int get_titlestart (int &len);  // get start x of title and length
  84.         int input (GetObj *Obj);        // Get a read from the screen
  85.         int create_get (int y, int x);  // create a new get object
  86.         void show_get (GetObj *Obj);    // Display get on screen with get attr
  87.         void draw_border ();            // draw the window border
  88.         virtual char bor_char (int, int, char &);// calculate the border char/attr
  89.         void update_scroll ();          // update scroll bars
  90.         virtual void display ();        // Display window contents on top
  91.         virtual void update (int start_pos,int len);  // Update a portion of window
  92.         void show_shadow ();            // Display the windows shadow.
  93.         virtual void mouse_routine (int y, int x); // mouse click routine 
  94.         mouse_routine_t mouse_user_routine; // programmers mouse routine
  95.  
  96.         /*  Paradox Stuf */
  97.         unsigned PX_tbl,                // Paradox table handle
  98.                  PX_rec;                // Paradox record handle
  99. public:
  100.         WinObj (int v_h=0, int v_w=0);
  101.         ~WinObj ();
  102.  
  103.         char *get_version ();
  104.         int set_virtual (int y,int x);      // set virtual size
  105.         virtual int open (int sr, int sc, int er, int ec,
  106.             int btype=W_DOUBLE, int wattr=_BLACK|LGREY,
  107.             int battr=_BLACK|LGREY);        // Open the window object
  108.  
  109.         /* Mouse related */
  110.         mouse_routine_t set_mouseroutine (mouse_routine_t); // programmers mouse routine 
  111.  
  112.         /* Attributes */
  113.         int set_attr (int color);           // Returns pervios attribute
  114.         void set_attr (int color, int y,
  115.                 int x, int cnt=1);          // change attr
  116.         void set_fill (char fill);          // set window fill character.
  117.         void change_border (int type,
  118.                 int color=-1);              // Set new border style/color
  119.         void title (char *str,
  120.                 int position=W_CENTER);     // Change the window title
  121.         virtual void shadow (int on_off=W_ON);      // Turn window shadow on/off
  122.  
  123.         /* Display routines */
  124.         void box (int sr, int sc, int er, 
  125.                 int ec, int type = W_SINGLE);       // Draw a box in the window
  126.         virtual void update ();             // Update but don't set current
  127.         void update_all ();                 // update all open windows
  128.         virtual void show_cursor ();        // Show cursor in window
  129.         virtual void close ();              // Close the window object.
  130.         virtual void set_active ();         // makes window current window
  131.         void bprintf (char *,...);          // Print f in window
  132.         void bprintf (int y, int x, char *,...);  // xy bprintf
  133.         void printf (char *,...);           // Print f in window
  134.         void printf (int y,int x,char *,...);    // xy printf
  135.         void puts (char *,int translate=W_ON);    // Display a string
  136.         void puts (int y, int x, char *, int translate=W_ON);
  137.         void putch (char ch, int translate=W_OFF);  // display a character
  138.         void putch (int y, int x, char ch, int translate=W_OFF);
  139.         int center (int y, char *);         // center in virtual window
  140.         void clr_win ();                    // Clear window
  141.         void clr_eol ();                    // Clear to end of current line
  142.         void clr_eow ();                    // Clear to end of window
  143.         void del_line (int line_no);        // Delete current, line pull up
  144.         void ins_line (int line_no);        // Ins new line, push down
  145.  
  146.         /* Get routines */
  147.         int get (int y, int x, char *str, char *picture=NULL);
  148.         int get (int y, int x, char *str, char style, int len = 0);
  149.         int get (int y, int x, char &ch);
  150.         int get (int y, int x, int &geti, int len=4);
  151.         int get (int y, int x, long int &getl,int len=5);
  152.         int get (int y, int x, double &getd, int len=10, int dec=2);
  153.         int set_getattr (int new_attr);  // Change the get attribute
  154.         int valid (valid_func func); // Valid function
  155.         int before (before_func func);    // Before get function
  156.         virtual int get_key (int echo=W_NOECHO, int seconds = 0);  // Get single key from keyboard  do not echo, wait forever
  157.         virtual int read (int clear = 1);           // Read all defined gets
  158.         int any_read_change ();                     // any change after last read
  159.         int update_gets ();                         // Update gets on screen.
  160.         void clear_gets ();                         // Clear all defined gets
  161.  
  162.         /* Window Movement */
  163.         virtual void hide ();                       // Hide window
  164.         virtual void unhide ();                     // Show window
  165.         virtual int move (int new_y, int new_x);    // Move the window
  166.         virtual int size (int new_height, int new_width);    // Resize the window
  167.         WinObj& gotoxy (int y=0, int x=0);          // Move cursor in window
  168.         int  pan (int delta_y, int delta_x);        // change pan location
  169.         int set_pan (int y, int x);                 // set pan location
  170.  
  171.         /* Information routines */
  172.         int do_youown (int y,int x,char &ch,char &attr);        // Do you own screen position
  173.         WinObj *who_owns (int y,int x,char &ch,char &attr);
  174.         WinObj *whos_below (int y, int x, char &ch, char &attr);
  175.         unsigned max_x(), max_y();                   // return maximum virtual x/y coordinates
  176.         int get_scr (int &sr, int &sc, int &er, int &ec);  // get coordinates
  177.         int get_pan (int &y, int &x);               // return current pan coordinates
  178.         int wherexy (int &y, int &x);               // return current cursor pos
  179.         int wherex ();                              // return current col
  180.         int wherey ();                              // return current row
  181.         int is_open ();                             // open status
  182.         int ret_char (int y, int x);                // get window char at window location
  183.         int ret_attr (int y, int x);                // get window attr at window location
  184.         int text_save (FILE *fp);                   // save window text
  185.         int text_retrieve (FILE *fp);               // retrieve window text
  186.  
  187.         /*   Paradox get / read routines  */
  188.         int PXrecord (unsigned tbl_handle, unsigned rec_handle);
  189.         int PXget (int y, int x, unsigned fld_handle);
  190.         int PXget (int y, int x, unsigned fld_handle, int len, int dec);
  191.         int PXget (int y, int x, unsigned fld_handle, char style);
  192.         int PXget (int y, int x, unsigned fld_handle, char *picture);
  193.         int PXread (int clear=1);             // use this read with PX
  194.  
  195.         /* Overloaded operators */
  196.         WinObj& operator << (int i);
  197.         WinObj& operator << (char *str);
  198.         WinObj& operator << (char ch);
  199.         WinObj& operator << (long l);
  200.         WinObj& operator << (double d);
  201.         WinObj& operator << (float f);
  202.         WinObj& operator << (unsigned ui);
  203.         WinObj& operator << (unsigned long ul);
  204. };
  205.  
  206. /*
  207.  * Global functions
  208.  */
  209. extern WinObj *Win_whos_active ();
  210. extern int printf_translate (int mode);
  211.  
  212. /*
  213.  * Some macros for internal use
  214.  */
  215. #define SHADOW_ATTR    DGREY
  216. #define BUFFER_OFFSET(y,x) (y * vw + x)
  217. #define GET_REAL_X(x) ((x - sx) + wsc + has_border)
  218. #define GET_REAL_Y(y) ((y - sy) + wsr + has_border)
  219. #define CALC_SCROLL_POSITION(s,x,a_rng,b_rng) ((a_rng) ? (s + 2 + (int)((long) (x) * (long)(b_rng) / (long)(a_rng))): 0)
  220.  
  221.  
  222. /*
  223.  * Class to save the current screen state to restore it when the
  224.  * program is finished.
  225.  */
  226. class ScreenState {
  227.     private:
  228.         int restore;        // restore state on exit flag
  229.         int page;           // previous screen page
  230.         int *scr_buf;       // screen buffer
  231.         int y, x;           // cursor location
  232.         int rows, cols;     // row/col count
  233.         int mode;
  234.     public:
  235.         ScreenState ();
  236.         ~ScreenState ();
  237. };
  238.  
  239.  
  240. #endif  //  #ifndef WINOBJ_HPP
  241.